const app = getApp();
const util = require('../../../utils/util.js');
const lbbService = require('../../../pages/service/service.js');
const lbbTaskService = require('../service/task-service.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        cityShow: '0',
        statusName:'已完成',
        isHandle:'1',
        statusList:[
            {
                label:'未完成',
                value:'0'
            },
            {
                label:'已完成',
                value:'1'
            },
        ],
        
        selectMonth:(new Date().getYear()+1900) + '-' +(new Date().getMonth()+1),
        status_animationData: {},
        month_animationData: {}, 
        markShow:false,

        minDate:new Date(2010, 0, 1).getTime(),
        currentDate:new Date().getTime(),
        showSignInFrom:false,
        pageNo:1,
        pageSize:10,
    },
    nextToDetail(e) {
        wx.navigateTo({
          url: '/pkgCost/pages/hospitalDetail/hospitalDetail?hospitalId='+this.data.hospitalInfo.id +'&versionIsNew={{item.versionIsNew}}&cityId=',
        })
    },
     //上拉加载更多
     eventhandle(e) {
        let that = this
        let pagenum = Number(that.data.pageNo)
        if (pagenum >= that.data.TotalPage) {
            that.setData({
                loading: false,
                loaded: true
            })
        } else {
            pagenum = pagenum + 1
            that.data.pageNo = pagenum.toString()
            that.setData({
                loading: true,
                loaded: false,
                pageNo:that.data.pageNo
            })
            that.getTaskList()
        }
    },
    //创建动画
    toggleAnimation: function(angle) {
        var animation = wx.createAnimation({
          timingFunction: "ease"
        })
        this.animation = animation;
        animation.rotate(angle).step()
    },
    statusToggle: function() {
        this.pickUp()
        if (this.data.cityShow=='2') {
          this.setData({
            cityShow: '0',
          })
        } else {
          this.toggleAnimation(180)
          this.setData({
            cityShow: '2',
          })
        }
        this.setData({
          status_animationData: this.animation.export()
        })
    },
    // cityToggle: function() {
    //     this.pickUp()
    //     if (this.data.cityShow=='2') {
    //       this.setData({
    //         cityShow: '0',
    //       })
    //     } else {
    //       this.toggleAnimation(180)
    //       this.setData({
    //         cityShow: '2',
    //       })
    //     }
    //     this.setData({
    //         city_animationData: this.animation.export()
    //     })
    // },
    monthToggle: function() {
        this.pickUp()
        if (this.data.cityShow=='1') {
          this.setData({
            cityShow: '0',
          })
        } else {
          this.toggleAnimation(180)
          this.setData({
            cityShow: '0',
            markShow:true
          })
        }
        this.setData({
          month_animationData: this.animation.export()
        })
    },
    formatDate(date) {
        date = new Date(date);
        return `${date.getYear() +1900 }-${date.getMonth() + 1}`;
    },
    onMarkClose() {
        this.toggleAnimation(0)
        this.setData({ markShow: false,month_animationData: this.animation.export() });
    },
    onMarkConfirm(event) {
        this.data.selectMonth = this.formatDate(event.detail)
        this.toggleAnimation(0)
        this.setData({
          markShow: false,
          selectMonth: this.data.selectMonth,
          cityShow: '0',
          month_animationData: this.animation.export()
        });
        this.getTaskList()
    },
    setStatus:function (e) {
        console.log("setUser-->",e)
       
        let statusIndex = e.target.dataset.index; //当前点击的索引
        let statusName = e.target.dataset.label;
        let isHandle = e.target.dataset.value;
        this.toggleAnimation(0)
        this.setData({
            cityShow: '0',
            statusIndex,
            isHandle,
            statusName,
            status_animationData: this.animation.export()
        })
        this.getTaskList()
    },
    cancelSelect: function(){
        this.pickUp()
        this.setData({
          cityShow: '0'
        })
    },
    pickUp: function(){
        if (this.data.cityShow == '1') {
            this.toggleAnimation(0)
            this.setData({
              month_animationData: this.animation.export()
            })
        } else if (this.data.cityShow == '2') {
          this.toggleAnimation(0)
          this.setData({
            status_animationData: this.animation.export()
          })
        }
    },
    // 跟进记录列表
    getTaskList(){
        let that = this
        let parmas = {
            pageNo:that.data.pageNo,
            pageSize:that.data.pageSize,
            hosId:that.data.hospitalInfo.id,
            month:that.data.selectMonth,
            isHandle:that.data.isHandle,
            userId:that.data.userId
        }
        wx.showLoading({
          title: '加载中',
        })
        lbbTaskService.mechanismFollowTaskList(parmas,function(res){
            if(that.data.pageNo==1) {
                let lists = [ ...res.data.records]
                if(lists.length==0) {
                    that.setData({
                        loading: false,
                        loaded: true,
                        TotalPage:res.data.pages,
                        taskList:lists
                    })
                    wx.hideLoading()
                } else {
                    that.setData({
                        loading: false,
                        loaded: true,
                        TotalPage:res.data.pages,
                        taskList:lists
                    })
                    wx.hideLoading()
                }
            } else {
                let lists = [...that.data.taskList, ...res.data.records]
                console.log(lists)
                if(lists.length==0) {
                    that.setData({
                        loading: false,
                        loaded: true,
                        TotalPage:res.data.pages,
                        taskList:lists
                    })
                    wx.hideLoading()
                } else {
                    that.setData({
                        loading: false,
                        loaded: true,
                        TotalPage:res.data.pages,
                        taskList:lists
                    })
                    wx.hideLoading()
                }
            }

        })
    },
     /**
     * 市场任务完成后操作
     */
    //标前沟通情况-已处理
    btnPreBidInteract(e) {
        let that = this
        lbbService.operationClick({
            taskId: e.currentTarget.dataset.taskid,
            operationType: e.currentTarget.dataset.operationtype
        }, function () {
            that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
            that.setData({
                taskList: that.data.taskList
            })
        })
        wx.navigateTo({
            url: `/pkgTask/pages/prebid-communication/index?taskId=${e.currentTarget.dataset.taskid}&type=${'pre_bid_communication'}&hospitalId=${that.data.hospitalInfo.id}&activeKey=${that.data.isHandle=='1' ? 3 : 0}`
        })
    },
    //院内招标说标-已处理
    btnInternalBidding(e) {
        let that = this
        lbbService.operationClick({
            taskId: e.currentTarget.dataset.taskid,
            operationType: e.currentTarget.dataset.operationtype
        }, function () {
            that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
            that.setData({
                taskList: that.data.taskList
            })
        })
        wx.navigateTo({
            url: `/pkgTask/pages/Internal-bidding/index?taskId=${e.currentTarget.dataset.taskid}&type=${'in_invite_bid'}&hospitalId=${that.data.hospitalInfo.id}&activeKey=${that.data.isHandle=='1' ? 3 : 0}`
        })
    },
    //代理商招标说标-已处理
    btnAgentBidding(e) {
        let that = this
        lbbService.operationClick({
            taskId: e.currentTarget.dataset.taskid,
            operationType: e.currentTarget.dataset.operationtype
        }, function () {
            that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
            that.setData({
                taskList: that.data.taskList
            })
        })
        wx.navigateTo({
            url: `/pkgTask/pages/Internal-bidding/index?taskId=${e.currentTarget.dataset.taskid}&type=${'assist_invite_bid'}&hospitalId=${that.data.hospitalInfo.id}&activeKey=${that.data.isHandle=='1' ? 3 : 0}`
        })
    },
    //医院沟通-已处理
    btnHospitalLink(e) {
        let that = this
        lbbService.operationClick({
            taskId: e.currentTarget.dataset.taskid,
            operationType: e.currentTarget.dataset.operationtype
        }, function () {
            if (e.currentTarget.dataset.tasktype == 1) {
                that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
                that.setData({
                    taskList: that.data.taskList
                })
            } else {
                that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
                that.setData({
                    taskList: that.data.taskList
                })
            }

        })
        wx.navigateTo({
            url: `/pkgTask/pages/prebid-communication/index?taskId=${e.currentTarget.dataset.taskid}&type=${'hospital_communication'}&hospitalId=${that.data.hospitalInfo.id}&taskType=${e.currentTarget.dataset.tasktype==1 ? 'long' : ''}&activeKey=${that.data.isHandle=='1' ? 3 : 0}`
        })
    },
    //医院关系维护-已处理
    btnHospitalDefend(e) {
        let that = this
        lbbService.operationClick({
            taskId: e.currentTarget.dataset.taskid,
            operationType: e.currentTarget.dataset.operationtype
        }, function () {
            that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
            that.setData({
                taskList: that.data.taskList
            })
        })
        wx.navigateTo({
            url: `/pkgTask/pages/maintenance-status/index?taskId=${e.currentTarget.dataset.taskid}&type=${'hospital_relationship'}&hospitalId=${that.data.hospitalInfo.id}&taskType=${e.currentTarget.dataset.tasktype==1 ? 'long' : ''}&activeKey=${that.data.isHandle=='1' ? 3 : 0}`
        })
    },
    //代理商沟通-已处理
    btnAgentLink(e) {
        let that = this
        lbbService.operationClick({
            taskId: e.currentTarget.dataset.taskid,
            operationType: e.currentTarget.dataset.operationtype
        }, function () {
            if (e.currentTarget.dataset.tasktype == 1) {
                that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
                that.setData({
                    taskList: that.data.taskList
                })
            } else {
                that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
                that.setData({
                    taskList: that.data.taskList
                })
            }

        })
        wx.navigateTo({
            url: `/pkgTask/pages/agent-link/index?taskId=${e.currentTarget.dataset.taskid}&type=${'agent_communication'}&hospitalId=${that.data.hospitalInfo.id}&taskType=${e.currentTarget.dataset.tasktype==1 ? 'long' : ''}&activeKey=${that.data.isHandle=='1' ? 3 : 0}`
        })
    },
    //代理商关系维护-已处理
    btnAgentDefend(e) {
        let that = this
        lbbService.operationClick({
            taskId: e.currentTarget.dataset.taskid,
            operationType: e.currentTarget.dataset.operationtype
        }, function () {
            that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
            that.setData({
                taskList: that.data.taskList
            })
        })
        wx.navigateTo({
            url: `/pkgTask/pages/maintenance-status/index?taskId=${e.currentTarget.dataset.taskid}&type=${'agent_relationship'}&hospitalId=${that.data.hospitalInfo.id}&taskType=${e.currentTarget.dataset.tasktype==1 ? 'long' : ''}&activeKey=${that.data.isHandle=='1' ? 3 : 0}`
        })
    },
    //代理商紧急情况沟通-已处理
    btnAgentUrgentLink(e) {
        let that = this
        lbbService.operationClick({
            taskId: e.currentTarget.dataset.taskid,
            operationType: e.currentTarget.dataset.operationtype
        }, function () {
            that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
            that.setData({
                taskList: that.data.taskList
            })
        })
        wx.navigateTo({
            url: `/pkgTask/pages/agent-link/index?taskId=${e.currentTarget.dataset.taskid}&type=${'agent_urgent_communication'}&hospitalId=${that.data.hospitalInfo.id}&activeKey=${that.data.isHandle=='1' ? 3 : 0}`
        })
    },
    //医院要求紧急拜访-已处理
    btnHospitalVisits(e) {
        let that = this
        lbbService.operationClick({
            taskId: e.currentTarget.dataset.taskid,
            operationType: e.currentTarget.dataset.operationtype
        }, function () {
            that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
            that.setData({
                taskList: that.data.taskList
            })
        })
        wx.navigateTo({
            url: `/pkgTask/pages/prebid-communication/index?taskId=${e.currentTarget.dataset.taskid}&type=${'hospital_urgent_communication'}&hospitalId=${that.data.hospitalInfo.id}&activeKey=${that.data.isHandle=='1' ? 3 : 0}`
        })
    },
    //看场地-已处理
    btnSite(e) {
        let that = this
        lbbService.operationClick({
            taskId: e.currentTarget.dataset.taskid,
            operationType: e.currentTarget.dataset.operationtype
        }, function () {
            that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
            that.setData({
                taskList: that.data.taskList
            })
        })
        wx.navigateTo({
            url: `/pkgTask/pages/look-site/index?taskId=${e.currentTarget.dataset.taskid}&hospitalId=${that.data.hospitalInfo.id}&activeKey=${that.data.isHandle=='1' ? 3 : 0}`
        })
    },
    //使用汇报-已处理
    btnUsage(e) {
        let that = this
        lbbService.operationClick({
            taskId: e.currentTarget.dataset.taskid,
            operationType: e.currentTarget.dataset.operationtype
        }, function () {
            that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
            that.setData({
                taskList: that.data.taskList
            })
        })
        wx.navigateTo({
            url: `/pkgTask/pages/usage-report/index?taskId=${e.currentTarget.dataset.taskid}&hospitalId=${that.data.hospitalInfo.id}&activeKey=${that.data.isHandle=='1' ? 3 : 0}`
        })
    },
    //合同处理-已处理
    btnContract(e) {
        let that = this
        lbbService.operationClick({
            taskId: e.currentTarget.dataset.taskid,
            operationType: e.currentTarget.dataset.operationtype
        }, function () {
            that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
            that.setData({
                taskList: that.data.taskList
            })
        })
        wx.navigateTo({
            url: `/pkgTask/pages/agent-link/index?taskId=${e.currentTarget.dataset.taskid}&type=${'handle_contract'}&hospitalId=${that.data.hospitalInfo.id}&activeKey=${that.data.isHandle=='1' ? 3 : 0}`
        })
    },
    //采集友商说标人信息-已处理
    btnFriendWord(e) {
        let that = this
        lbbService.operationClick({
            taskId: e.currentTarget.dataset.taskid,
            operationType: e.currentTarget.dataset.operationtype
        }, function () {
            that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
            that.setData({
                taskList: that.data.taskList
            })
        })
        wx.navigateTo({
            url: `/pkgTask/pages/agent-information/index?taskId=${e.currentTarget.dataset.taskid}&hospitalId=${that.data.hospitalInfo.id}&activeKey=${that.data.isHandle=='1' ? 3 : 0}`
        })
    },
    //采集医院信息 -已处理
    btnHospitalWord(e) {
        let that = this
        lbbService.operationClick({
            taskId: e.currentTarget.dataset.taskid,
            operationType: e.currentTarget.dataset.operationtype
        }, function () {
            if (e.currentTarget.dataset.tasktype == 1) {
                that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
                that.setData({
                    taskList: that.data.taskList
                })
            } else {
                that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
                that.setData({
                    taskList: that.data.taskList
                })
            }
        })
        wx.navigateTo({
            url: `/pkgTask/pages/hospital-Information/index?taskId=${e.currentTarget.dataset.taskid}&hospitalId=${that.data.hospitalInfo.id}&taskType=${e.currentTarget.dataset.tasktype==1 ? 'long' : '' }&activeKey=${that.data.isHandle=='1' ? 3 : 0}`
        })
    },
    //友商说标人沟通情况-已处理
    btnCommunicationWordSpeaker(e) {
        let that = this
        lbbService.operationClick({
            taskId: e.currentTarget.dataset.taskid,
            operationType: e.currentTarget.dataset.operationtype
        }, function () {
            that.data.taskList[e.currentTarget.dataset.index].operationList[e.currentTarget.dataset.indext].clickStatus = 1
            that.setData({
                taskList: that.data.taskList
            })
        })
        wx.navigateTo({
            url: `/pkgTask/pages/speaker-communication/index?taskId=${e.currentTarget.dataset.taskid}&hospitalId=${that.data.hospitalInfo.id}&activeKey=${that.data.isHandle=='1' ? 3 : 0}`
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log(JSON.parse(options.hospitalInfo))
        this.setData({
            hospitalInfo:JSON.parse(options.hospitalInfo),
            userId:options.userId
        })
        this.getTaskList()
    },

    //市场临时任务完成
    async goHandle(e) {
        console.log('去处理------>', e)
        let that = this
        // await that.getWXLocation(that)
        that.setData({
            signOrachieve: 'achieve',
            taskId: e.currentTarget.dataset.id,
        })
        if (e.currentTarget.dataset.issignin) {
            if (e.currentTarget.dataset.operationlist?.length <= 0) {
                await that.getWXLocation(that)
                if (e.currentTarget.dataset.tasktype==1) {
                    lbbService.TaskItemsOk({
                        taskLongStateId: e.currentTarget.dataset.id,
                        handleLocation: that.data.addressDetail
                    }, function (res) {
                        if (that.data.taskList.length == 1) {
                            that.setData({
                                city: '',
                                grade: '',
                            })
                        }
                        that.setData({
                            page: '1',
                            taskList: []
                        })
                        that.getTaskList()
                        // that.getTaskListNumber()
                    })
                } else {
                    lbbService.HandleOk({
                        taskDevOpsId: that.data.taskId,
                        handleDesc: that.data.textArea ? that.data.textArea : '',
                        handleLocation: that.data.addressDetail
                    }, function (res) {
                        if (that.data.taskList.length == 1) {
                            that.setData({
                                city: '',
                                grade: '',
                            })
                        }
                        that.setData({
                            page: '1',
                            hosPatrolList: [],
                            taskList: [],
                            taskList: []
                        })
                        that.getTaskList()
                        that.setData({
                            textArea: null,
                            showFrom: false
                        })
                    })
                }
            } else {
                that.setData({
                    showFrom: true,
                    selectHospitalId: that.data.hospitalInfo.id,
                    configOperationlist: e.currentTarget.dataset.operationlist,
                    selectTasktype: e.currentTarget.dataset.tasktype==1 ? 'long' : '',
                })
            }
        } else {
            wx.showToast({
                title: '请先完成签到',
                icon: 'error',
                duration: 1000
            })
        }

    },
    //点击完成任务的弹窗列表
    goOperatePage(e) {
        console.log(e,111111)
        let operationTypeCode = e.currentTarget.dataset.operationtypecode
        let taskid = e.currentTarget.dataset.taskid
        if(this.data.selectTasktype=='long'){
            this.counterPageLong(operationTypeCode, taskid)
        }else{
            this.counterPage(operationTypeCode, taskid)
        }
    },
    //去未操作提交页面的判断
    counterPage(code, taskid) {
        let configOperationlist = JSON.stringify(this.data.configOperationlist)
        if (code == 'B19A03A01A01') {
            wx.navigateTo({
                url: `/pkgTask/pages/prebid-communication/index?taskId=${taskid}&type=${'pre_bid_communication'}&hospitalId=${this.data.selectHospitalId}&operationlist=${configOperationlist}&operationTypeCode=B19A03A01A01`
            })
        } else if (code == 'B19A03A01A02') {
            wx.navigateTo({
                url: `/pkgTask/pages/Internal-bidding/index?taskId=${taskid}&type=${'in_invite_bid'}&hospitalId=${this.data.selectHospitalId}&operationlist=${configOperationlist}&operationTypeCode=B19A03A01A02`
            })
        } else if (code == 'B19A03A01A03') {
            wx.navigateTo({
                url: `/pkgTask/pages/Internal-bidding/index?taskId=${taskid}&type=${'assist_invite_bid'}&hospitalId=${this.data.selectHospitalId}&operationlist=${configOperationlist}&operationTypeCode=B19A03A01A03`
            })
        } else if (code == 'B19A03A01A04') {
            wx.navigateTo({
                url: `/pkgTask/pages/hospital-Information/index?taskId=${taskid}&hospitalId=${this.data.selectHospitalId}&taskType=${this.data.selectTasktype}&operationlist=${configOperationlist}&operationTypeCode=B19A03A01A04`
            })
        } else if (code == 'B19A03A01A05') {
            wx.navigateTo({
                url: `/pkgTask/pages/agent-link/index?taskId=${taskid}&type=${'agent_communication'}&hospitalId=${this.data.selectHospitalId}&taskType=${this.data.selectTasktype}&operationlist=${configOperationlist}&operationTypeCode=B19A03A01A05`
            })
        } else if (code == 'B19A03A01A06') {
            wx.navigateTo({
                url: `/pkgTask/pages/prebid-communication/index?taskId=${taskid}&type=${'hospital_communication'}&hospitalId=${this.data.selectHospitalId}&taskType=${this.data.selectTasktype}&operationlist=${configOperationlist}&operationTypeCode=B19A03A01A06`
            })
        } else if (code == 'B19A03A01A07') {
            wx.navigateTo({
                url: `/pkgTask/pages/look-site/index?taskId=${taskid}&hospitalId=${this.data.selectHospitalId}&operationlist=${configOperationlist}&operationTypeCode=B19A03A01A07`
            })
        } else if (code == 'B19A03A01A08') {
            wx.navigateTo({
                url: `/pkgTask/pages/usage-report/index?taskId=${taskid}&hospitalId=${this.data.selectHospitalId}&operationlist=${configOperationlist}&operationTypeCode=B19A03A01A08`
            })
        } else if (code == 'B19A03A01A09') {
            wx.navigateTo({
                url: `/pkgTask/pages/agent-information/index?taskId=${taskid}&hospitalId=${this.data.selectHospitalId}&operationlist=${configOperationlist}&operationTypeCode=B19A03A01A09`
            })
        } else if (code == 'B19A03A01A10') {
            wx.navigateTo({
                url: `/pkgTask/pages/agent-link/index?taskId=${taskid}&type=${'handle_contract'}&hospitalId=${this.data.selectHospitalId}&operationlist=${configOperationlist}&operationTypeCode=B19A03A01A10`
            })
        } else if (code == 'B19A03A01A11') {
            wx.navigateTo({
                url: `/pkgTask/pages/agent-link/index?taskId=${taskid}&type=${'agent_urgent_communication'}&hospitalId=${this.data.selectHospitalId}&operationlist=${configOperationlist}&operationTypeCode=B19A03A01A11`
            })
        } else if (code == 'B19A03A01A12') {
            wx.navigateTo({
                url: `/pkgTask/pages/prebid-communication/index?taskId=${taskid}&type=${'hospital_urgent_communication'}&hospitalId=${this.data.selectHospitalId}&operationlist=${configOperationlist}&operationTypeCode=B19A03A01A12`
            })
        }
    },
    counterPageLong(code, taskid) {
        let that=this
        let configOperationlist = JSON.stringify(this.data.configOperationlist)
        if (code == 'B19A04A01A01') {
            wx.navigateTo({
                url: `/pkgTask/pages/prebid-communication/index?taskId=${taskid}&type=${'pre_bid_communication'}&hospitalId=${this.data.selectHospitalId}&operationlist=${configOperationlist}&taskType=${this.data.selectTasktype}&activeKey=${that.data.isHandle=='1' ? 3 : 0}&operationTypeCode=B19A04A01A01`
            })
        } else if (code == 'B19A04A01A05') {
            wx.navigateTo({
                url: `/pkgTask/pages/maintenance-status/index?taskId=${taskid}&type=${'agent_relationship'}&hospitalId=${this.data.selectHospitalId}&taskType=${this.data.selectTasktype}&activeKey=${that.data.isHandle=='1' ? 3 : 0}&operationlist=${configOperationlist}&operationTypeCode=B19A04A01A05`
            })
        } else if (code == 'B19A04A01A03') {
            wx.navigateTo({
                url: `/pkgTask/pages/hospital-Information/index?taskId=${taskid}&hospitalId=${this.data.selectHospitalId}&taskType=${this.data.selectTasktype}&activeKey=${that.data.isHandle=='1' ? 3 : 0}&operationlist=${configOperationlist}&operationTypeCode=B19A04A01A03`
            })
        } else if (code == 'B19A04A01A02') {
            wx.navigateTo({
                url: `/pkgTask/pages/agent-link/index?taskId=${taskid}&type=${'agent_communication'}&hospitalId=${this.data.selectHospitalId}&taskType=${this.data.selectTasktype}&operationlist=${configOperationlist}&activeKey=${that.data.isHandle=='1' ? 3 : 0}&operationTypeCode=B19A04A01A02`
            })
        } else if (code == 'B19A04A01A06') {
            wx.navigateTo({
                    url: `/pkgTask/pages/maintenance-status/index?taskId=${taskid}&type=${'hospital_relationship'}&hospitalId=${this.data.selectHospitalId}&taskType=${this.data.selectTasktype}&activeKey=${that.data.isHandle=='1' ? 3 : 0}&operationlist=${configOperationlist}&operationTypeCode=B19A04A01A06`
            })
        } else if (code == 'B19A04A01A07') {
            wx.navigateTo({
                url: `/pkgTask/pages/speaker-communication/index?taskId=${taskid}&hospitalId=${this.data.selectHospitalId}&activeKey=${that.data.isHandle=='1' ? 3 : 0}&taskType=${this.data.selectTasktype}&operationlist=${configOperationlist}&operationTypeCode=B19A04A01A07`
            })
        } 
    },
    // 输入框内容
    bindAreaChange(e) {
        let that = this
        that.setData({
            textArea: e.detail.value
        })
    },
    // 输入框确定按钮
    okRemarks() {
        let that = this
        console.log('3333', this.data.textArea, that.data.taskId)
        lbbService.HandleOk({
            taskDevOpsId: that.data.taskId,
            handleDesc: that.data.textArea ? that.data.textArea : '',
            handleLocation: that.data.addressDetail
        }, function (res) {
            if (that.data.taskList.length == 1) {
                that.setData({
                    city: '',
                    grade: '',
                })
            }
            that.setData({
                page: '1',
                hosPatrolList: [],
                taskList: [],
                taskList: []
            })
            that.getTaskList()
            that.setData({
                textArea: null,
                showFrom: false
            })
        })
    },
    //市场长期任务点击完成
    tocomplete: async function (e) {
        let that = this
        that.setData({
            // showFrom: true,
            // taskId: e.currentTarget.dataset.id,
            signOrachieve: 'achieve'
        })
        await that.getWXLocation(that)
        wx.showModal({
            title: '完成',
            content: `您确定完成${e.currentTarget.dataset.name}吗？`,
            showCancel: true,
            confirmText: '确定',
            success(res) {
                if (res.confirm) {
                    lbbService.TaskItemsOk({
                        taskLongStateId: e.currentTarget.dataset.id,
                        handleLocation: that.data.addressDetail
                    }, function (res) {
                        if (that.data.taskList.length == 1) {
                            that.setData({
                                city: '',
                                grade: '',
                            })
                        }
                        that.setData({
                            page: '1',
                            taskList: []
                        })
                        that.getTaskList()
                        // that.getTaskListNumber()
                    })
                }
            }
        })
    },
    //点击签到获取当前位置
    getWXLocation: (thats) => {
        wx.showLoading({
            title: '定位中...',
            mask: true,
        })
        return new Promise((resolve, reject) => {
            let _locationChangeFn = (res) => {
                resolve(res);
                thats.setData({
                    latitude: res.latitude,
                    longitude: res.longitude
                })
                thats.getAddress()
                wx.hideLoading()
                wx.offLocationChangeError(_locationChangeFn)
                wx.offLocationChange(_locationChangeFn)
                wx.stopLocationUpdate()
            }
            wx.startLocationUpdate({
                success: (res) => {
                    wx.onLocationChangeError(_locationChangeFn)
                    wx.onLocationChange(_locationChangeFn)
                },
                fail: (err) => {
                    wx.hideLoading()
                    reject()
                    thats.getAddress()
                }
            })
        })
    },
    //查看签到
    checkIn: function (e) {
        lbbService.getSignInInfo({
            mechanismId: that.data.hospitalInfo.id,
            userId: this.data.userId,
            placeType: e.currentTarget.dataset.placetype
        }, function (res) {
            wx.showModal({
                title: '签到信息',
                content: '签到时间：' + res.data.signInDate + '\r\n' + '签到地点：' + res.data.location,
                showCancel: false,
            })
        })
    },
    //完成任务签到
    okSignIn() {
        let that = this
        console.log(that.data.remImages)
        if (!that.data.remImages || that.data.remImages?.length <= 0) {
            wx.showToast({
                title: '请上传图片！',
                icon: 'error',
                duration: 1000
            })
            return
        }
        that.marketTemporarySignInExecute(that.data.addressDetail, that.data.marketSignInText, that.data.remImages)
        
    },
    //签到备注
    marketSignInAreaChange(e) {
        this.setData({
            marketSignInText: e.detail.value
        })
    },
    //上传图片
    setImgArr(e) {
        let that = this
        let imgArray = e.detail;
        let newUpLoadImg = []
        let oldUpLoadImg = []
        imgArray.forEach(item => {
            if (item.indexOf('http://tmp/') != -1 || item.indexOf('wxfile://tmp') != -1) {
                newUpLoadImg.push(item)
            } else {
                oldUpLoadImg.push(item)
            }
        })
        util.newUpLoadImg(app.globalData.header, newUpLoadImg, 0, [], function (imgIdArray) {
            console.log(8888,imgIdArray)
            oldUpLoadImg.push(...imgIdArray)
            that.setData({
                remImages: oldUpLoadImg
            })
        });
    },
    //取消任务签到
    cancelSignIn() {
        let that = this
        console.log(11111)
        // that.setData({
        //     showSignInFrom: false
        // })
    },
    //市场任务签到接口
    marketTemporarySignInExecute(address, marketRemark, remImages) {
        let that = this
        lbbService.taskMarketSignIn({
            taskId: that.data.marketTaskid,
            taskType: that.data.marketTaskType == 0 ? 1 : 0,
            latitude: that.data.latitude,
            longitude: that.data.longitude,
            location: address,
            remark: marketRemark ? marketRemark : '',
            images: remImages ? remImages.toString() : ''
        }, function (res) {
            console.log('市场签到回调', res, that.data.taskList)
            if (that.data.marketTaskType == 0) {
                that.data.taskList[that.data.marketIndex].isSignIn = 1
                that.setData({
                    showSignInFrom: false,
                    taskList: that.data.taskList
                })
            } else {
                that.data.taskList[that.data.marketIndex].isSignIn = 1
                that.setData({
                    showSignInFrom: false,
                    taskList: that.data.taskList,
                })
            }

        })
    },
    //市场任务查看签到
    marketTemporaryCheckIn(e) {
        let that = this
        lbbService.taskMarketSignInInfo({
            taskId: e.currentTarget.dataset.taskid,
            taskType: that.data.marketTaskType == 0 ? 1 : 0
        }, function (res) {
            if (res.data.images) {
                res.data.images = res.data.images.split(',')
            }
            that.setData({
                showCheckIn: true,
                signInData: res.data
            })
            // wx.showModal({
            //     title: '签到信息',
            //     content: '签到时间：' + res.data.signInDate + '\r\n' + '签到地点：' + res.data.location + '\r\n' + '签到备注：' + `${res.data.remark?res.data.remark:'无'}`,
            //     showCancel: false,
            // })
        })
    },
    //根据经纬度获取详细地址
    getAddress: function () {
        let that = this
        wx.request({
            url: 'https://api.map.baidu.com/geocoder/v2/',
            method: 'GET',
            data: {
                location: that.data.latitude + ',' + that.data.longitude,
                output: 'json',
                coordtype: 'wgs84ll',
                pois: 1,
                s: 1,
                latest_admin: 1,
                ak: 'GQKwKHdtu8CgmxXIkXdyTkdtlfvML4Gg'
            },
            success(res) {
                console.log('>>', res)
                if (res.data.status == 0 && res.data.result.formatted_address) {
                    let address = res.data.result.formatted_address
                    that.setData({
                        addressDetail: address
                    })
                    that.setData({
                        showSignInFrom: true,
                        marketSignInText: '',
                        remImages: []
                    })
                } else {
                    wx.showToast({
                        title: '获取位置失败,请打开手机定位重新签到',
                        icon: 'none',
                        duration: 3000
                    })
                }
            },
            fail() {
                that.setData({
                    address: null,
                })
            }
        })
    },
    addNewTask: function() {
        wx.navigateTo({
          url: '/pkgTask/pages/addTaskModel/addTaskModel?userId='+this.data.userId+'&hosId='+this.data.hospitalInfo.id+'&hosName='+this.data.hospitalInfo.hosName,
        })
    },
    //市场任务签到获取当前位置
    async marketTemporarySignIn(e) {
        let that = this
        that.setData({
            marketTaskid: e.currentTarget.dataset.taskid,
            marketIndex: e.currentTarget.dataset.index,
            marketTaskType: e.currentTarget.dataset.taskType==1 ? 0 : 1,
            signOrachieve: 'sign'
        })
        let location = null;
        try {
            location = await that.getWXLocation(that)
        } catch (err) {}
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        this.setData({
            taskList:[],
            maintenancetasks: [],
            page: '1',
            showFrom: false
        })
        this.getTaskList();
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})